package com.peakmain.systemmoudle.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.peakmain.sysemmoudle.R;
import com.peakmain.sysemmoudle.R2;
import com.peakmain.systemmoudle.adapter.ViewPagerAdapter;
import com.peakmain.systemmoudle.bean.FragmentInfo;
import com.peakmain.systemmoudle.fragment.SystemListFragment;
import com.peakmain.wanandroid.netmodule.base.BaseActivity;
import com.peakmain.wanandroid.netmodule.bean.system.SystemTreeBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * author: peakmain
 * createdata：2019/7/16
 * mail: 2726449200@qq.com
 * desiption:
 */
public class SystemListActivity extends BaseActivity {
    @BindView(R2.id.tab_layout)
    TabLayout mTabLayout;
    @BindView(R2.id.view_pager)
    ViewPager mViewPager;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_system_list;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        int position = getIntent().getIntExtra("position", 0);
        List<SystemTreeBean.ChildrenBean> childrenBeans= (List<SystemTreeBean.ChildrenBean>) getIntent().getSerializableExtra("children");
        List<FragmentInfo> fragmentInfos = new ArrayList<>();
        for (int i = 0; i < childrenBeans.size(); i++) {
            SystemTreeBean.ChildrenBean childrenBean = childrenBeans.get(i);
            int id = childrenBean.getId();
            fragmentInfos.add(new FragmentInfo(childrenBean.getName(), SystemListFragment.getInstance(id)));
        }
        ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(),fragmentInfos);
        //viewpager设置适配器
        mViewPager.setAdapter(pagerAdapter);
        //TableLayout和ViewPager进行绑定
        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.setCurrentItem(position);
    }

}
